package com.zxbg.dao;

import com.zxbg.domain.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface EmployeeDao {
    @Select("select * from employee where employee_id = #{employee_id} and login_password = #{password} and tenant_id = #{tenant_id}")
    public Employee getEmployeeByEmployeeIdAndPassword(@Param("employee_id") String employee_id, @Param("password") String password, @Param("tenant_id") Integer tenant_id);

    @Select("select * from employee where employee_id = #{employee_id} and login_password = #{password}")
    public Employee getEmployeeByEmployeeIdAndPasswordNull(@Param("employee_id") String employee_id, @Param("password") String password);

    @Select("select count(*) from employee where tenant_id = #{tenant_id}")
    public int getCount(Integer tenant_id);

    @Select("select * from employee where employee_id = #{employee_id} and tenant_id = #{tenant_id}")
    public Employee getEmployeeByEmployeeId(@Param("employee_id") String employee_id, @Param("tenant_id") Integer tenant_id);

    @Select("select * from employee where employee_name like #{employee_name} and status = 1")
    public List<Employee> getEmployeeByName(String employee_name);

    @Select("select * from employee where work_id = #{work_id} and tenant_id = #{tenant_id}")
    public Employee getEmployeeByWorkId(@Param("work_id") String work_id, @Param("tenant_id") Integer tenant_id);

    @Insert("insert into employee values(#{employee_id}, #{employee_name}, #{leader_id}, #{leader_name}, null, #{tenant_id}, #{main_dept_id}, #{all_dept_id}, #{department_name}, #{login_password}, 1, #{sex}, #{line_number}, #{phone_number}, #{email}, #{work_id}, null, null, #{duty}, #{responsible_dept_id}, #{order}, 0)")
    public int addEmployee(Employee employee);

    @Update("update employee set `${key}` = #{value} where employee_id = #{employee_id} and tenant_id = #{tenant_id}")
    public int updateSomeIByEmployeeId(@Param("employee_id") String employee_id, @Param("key") String key, @Param("value") Integer value, @Param("tenant_id") Integer tenant_id);

    @Update("update employee set `${key}` = #{value} where employee_id = #{employee_id} and tenant_id = #{tenant_id}")
    public int updateSomeVByEmployeeId(@Param("employee_id") String employee_id, @Param("key") String key, @Param("value") String value, @Param("tenant_id") Integer tenant_id);

    @Update("update employee set `status` = #{status} where employee_id = #{employee_id} and tenant_id = #{tenant_id}")
    public int changeEmployeeStatus(@Param("employee_id") String employee_id, @Param("tenant_id") Integer tenant_id, @Param("status") Integer status);

    @Update("update employee set login_password = #{new_password} where employee_id = #{employee_id} and tenant_id = #{tenant_id}")
    public int changePassword(@Param("employee_id") String employee_id, @Param("new_password") String new_password, @Param("tenant_id") Integer tenant_id);

    @Update("update employee set responsible_dept_id = #{responsible_dept_id} where employee_id = #{employee_id} and tenant_id = #{tenant_id}")
    public int setResponseDeptByEmployeeId(@Param("employee_id") String employee_id, @Param("responsible_dept_id") String responsible_dept_id, @Param("tenant_id") Integer tenant_id);

    @Update("update employee set is_sysadmin = #{is_sysadmin} where employee_id =#{employee_id} and tenant_id = #{tenant_id}")
    public int setIfSysadminByEmployeeId(@Param("employee_id") String employee_id, @Param("is_sysadmin") Integer is_sysadmin, @Param("tenant_id") Integer tenant_id);

    @Update("update employee set picture = #{picture} where employee_id = #{employee_id} and tenant_id = #{tenant_id}")
    public int updateAvatarImg(@Param("picture") String picture, @Param("employee_id") String employee_id, @Param("tenant_id") Integer tenant_id);

    @Select("select * from employee where status = 1 and tenant_id = #{tenant_id}")
    public List<Employee> getAllUseEmployee(Integer tenant_id);

    @Update("update employee set last_use_app_id = #{last_use_app_id} where employee_id = #{employee_id} and tenant_id = #{tenant_id}")
    public int updateLastUseApp(@Param("employee_id") String employee_id, @Param("last_use_app_id") String last_use_app_id, @Param("tenant_id") Integer tenant_id);

    @Update("update employee set selected_app_id = #{selected_app_id} where employee_id = #{employee_id} and tenant_id = #{tenant_id}")
    public int updateSelectedApp(@Param("selected_app_id") String selected_app_id, @Param("employee_id") String employee_id, @Param("tenant_id") Integer tenant_id);
}
